// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// o [author] rhyme_lph
// S [email]  rhymelph@gmail.com
// q [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/entities/income_type_entity.dart';
import 'package:finance_app/src/http_service/http_setting_service.dart';
import 'package:finance_app/src/mixin/search_data_list_mixin.dart';
import 'package:finance_app/src/widgets/bottom_sheet/add_income_type_bottom_sheet.dart';
import 'package:flutter/material.dart';

class SelectIncomeTypeProvider extends BaseProvider<List<IncomeTypeEntity>>
    with SearchDataListMixin {
  String currency;

  IncomeTypeEntity currentSelect;

  @override
  Future get dataFuture => HttpSettingService.getIncomeType();

  @override
  void searchRefreshData(searchData) {}

  void onNavAddIncomeType() {
    obtainContext?.call((context) async {
      final result = await showAddIncomeTypeBottomSheet(
          context, null, null, null, 0, true);
      if (result != null) {
        Navigator.of(context).pop({
          'title': result['incomeType'],
          'controller': TextEditingController(text: result['amount']),
          'focusNode': FocusNode(),
          'currency': currency,
          'cpfPayable': result['cpfPayable'],
          'wageType': result['wageType'],
        });
      }
    });
  }

  void onSelect(IncomeTypeEntity item) async {
    // currentSelect = item;
    // update();
    obtainContext?.call((context) async {
      final result = await showAddIncomeTypeBottomSheet(
          context, null, item.name, item.wageType, item.cpfPayable, false);
      if (result != null) {
        Navigator.of(context).pop({
          'title': result['incomeType'],
          'controller': TextEditingController(text: result['amount']),
          'focusNode': FocusNode(),
          'currency': currency,
          'cpf': result['cpf'],
        });
      }
    });
  }
}
